<template>
	<view>
		<view class="uni-status-bar" style="background:rgba(233, 233, 233, 1)"></view>
		<view class="hb-header">
			<view class="left">
				<view class="uni-page-head-btn"><i class="uni-btn-icon" style="color: rgb(0, 0, 0); font-size: 27px;"
						@click="back"></i></view>
			</view>
			<view class="title">{{$t('index.news')}}</view>
			<view class="right">
				{{$t('index.news.ready')}}
			</view>
		</view>
		<view class="tab flexSpace">
			<view class="item" :class="tabIndex == 0 ?'active':''" @click="ontab(0)">
				{{$t('index.news.sys')}}
				<text></text>
			</view>
			<view class="item" :class="tabIndex == 1 ?'active':''" @click="ontab(1)">
				{{$t('index.news.mynews')}}
				<text></text>
			</view>
		</view>
		<view class="content" v-if="tabIndex == 0">
			<view class="item" v-for="item in dataList" :data="item" :key="item.id"
				@click="onNative('/pages/information/detail?id='+item.id)">
				<view class="title flexSpace">
					<view class="label">{{item.title}}</view>
				</view>
				<view class="flexSpace">
					<view class="text">{{item.summary}}</view>
					<view class="time">{{item.created_at.slice(0,10)}}</view>
				</view>
			</view>
			<uniLoadMore :loadingType="loadingType" :contentText="contentText"></uniLoadMore>
		</view>
		<view v-else style="color: #999;text-align: center;margin:50rpx">
			{{$t('info.open')}}
		</view>
		
	</view>
</template>

<script>
	import {
		newsList
	} from '@/api/home'
	import uniLoadMore from '@/components/uni-load-more.vue';
	import base64Code from '@/plugin/base64code';
	export default {
		components:{
			uniLoadMore
		},
		data() {
			return {
				tabIndex: 0,
				loadingType: 0,
				dataList: [],
				page: 1,
				total:0
			}
		},
		created() {
			this.getnewsList()
		},
		computed:{
			contentText(){
				return{
					contentdown: this.$t('info.contentText.contentdown'),
					contentrefresh: this.$t('info.contentText.contentrefresh'),
					contentnomore: this.$t('info.contentText.contentnomore')
				}
			}
		},
		methods: {
			back() {
				uni.navigateBack({
					delta: 1
				});
			},
			ontab(index) {
				if (this.tabIndex != index) {
					this.tabIndex = index
				}
			},
			onNative(url) {
				uni.navigateTo({
					url: url
				})
			},
			//获取公告列表
			getnewsList(bol) {
				this.loadingType = 1;
				var time = Math.round(new Date().getTime() / 1000);
				var data = {
					page: base64Code.adds(time, this.page),
					time: time
				}
				newsList(data).then(res => {
					if (res.code = '1000') {
						if (bol) {
							this.dataList = [];
						}
						console.log(res.data,"res.data666")
						this.total =res.data.total
						let arr = res.data.model
						this.dataList.push(...arr)
					} else {
						this.loadingType = 3
						this.dataList = [];
					}
				}).catch(() => {
					this.loadingType = 3
				})
			},
			onPullDownRefresh() {
				this.page = 1;
				this.loadingType = 0;
				this.getnewsList(true);
			},
			onReachBottom() {
				if (this.loadingType !== 0) {
					return
				}
				this.getnewsList();
			}
		}
	}
</script>

<style scoped lang="scss">
	.hb-header {
		background: rgba(233, 233, 233, 1);
	}

	.tab {
		padding: 40rpx 100rpx 24rpx 100rpx;
		border-bottom: .5px solid $hb-border-color;

		.item {
			font-size: 32rpx;
			color: $hb-text-gray-color;
			position: relative;

			text {
				position: absolute;
				left: 30%;
				bottom: -26rpx;
				width: 40rpx;
				height: 4rpx;
				background: rgba(0, 0, 0, 0);
			}

			&.active {
				color: $hb-text-black-color;

				text {
					background: $hb-text-black-color;
				}
			}
		}
	}

	.content {
		padding: 0 32rpx;

		.item {
			padding: 32rpx 0;
			border-bottom: .5px solid $hb-border-color;

			.title {
				font-size:16px;
				color: $hb-text-black-color;
				margin-bottom: 20rpx;
				align-items: center;

				.label {
					width: 90%;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}

				.icon {
					width: 14rpx;
					height: 14rpx;
					border-radius: 50%;
					background: #f00;
				}
			}

			.text {
				font-size: 28rpx;
				width: 70%;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				color: $hb-text-gray-color;
			}

			.time {
				font-size: 24rpx;
				color: $hb-text-gray-color;
			}
		}
	}
</style>
